﻿var tabidcounter = 0; var accordion = null; var grid = null, myTree = null;
var url = "Main.aspx?";

$(document).ready(function () {
    //布局
    $("#mainmenu").ligerLayout({ leftWidth: 250, height: '100%', heightDiff: -1, space: 2, onHeightChanged: f_heightChanged, allowLeftResize: false });
    var height = $(".l-layout-center").height();

    $(".l-link").hover(function () { $(this).addClass("l-link-over"); }, function () { $(this).removeClass("l-link-over"); });
    accordion = $("#accordion1").ligerGetAccordionManager();

    $("#tblMenu tbody td").hover(function () { $(this).css("background", "#004B7C"); }, function () { $(this).css("background", "#1F7FB6"); });

    if (tg != "") {
        var arrParam = tg.split("&"); var funID = arrParam[0].split("=")[1];
        OpenFunction(funID);
    }

    //面板
    $("#accordion1").ligerAccordion({ height: height - 60 - 15 - 27, speed: null });

    /* Slide Toogle */
    $("ul.expmenu li > div.header").click(function () {
        var arrow = $(this).find("span.arrow");

        if (arrow.hasClass("up")) {
            arrow.removeClass("up");
            arrow.addClass("down");
        }
        else if (arrow.hasClass("down")) {
            arrow.removeClass("down");
            arrow.addClass("up");
        }

        $(this).parent().find("ul.menu").slideToggle();
    });
});


//打开功能页面
function OpenFunction(_funID) {
    switch (_funID) {
        case "FA01": //Budget Management
            ShowDetail("Business/Budget.aspx", $('#lblBudget').html());
            break;
        case "FA02": //Task Management
            ShowDetail("Task.aspx");
            ShowDetail("Business/Task.aspx", $('#lblTask').html());
            break;
        case "FA03": //Subtask Management
            ShowDetail("Business/Subtask.aspx", $('#lblSubtask').html());
            break;
        case "FA04": //Labor Hours Management
            ShowDetail("Business/LaborHours.aspx", $('#lblLaborHours').html());
            break;
        case "FA05": //Additional HRS Request
            ShowDetail("Business/AdditionalHRS.aspx", $('#lblAdditionalHRS').html());
            break;
    }
}

function f_heightChanged(options) {
    if (accordion && options.middleHeight - 24 > 0) accordion.setHeight(options.middleHeight - 24);
}

function ShowDetail(_url, _title) {
    if (_url == '') { alert("Unrealized"); return; }
    $("#frmApply").attr("src", _url);
    if (_title != "")
        ShowTitle(_title);
}

function ShowTitle(_title) {
    $(document)[0].title = "[XXXXX System]  >> " + _title;
}


function LogOut() { if (confirm("Are you sure to log out/确定退出?")) return true; else return false; }

window.onbeforeunload = function () {
    var isClose = false;
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

    if (Sys.ie == 6.0) {
        if (event.clientX < 0 && event.clientY < 0 || event.altKey) { //防止刷新动作
            isClose = true;
        }
        else if ((event.clientY < 0 || event.clientY > document.body.clientHeight) || event.altKey) {//防止刷新动作
            isClose = true;
        }
    }
    else {
        if ((event.clientY < 0 || event.clientY > document.body.clientHeight) || event.altKey) {//防止刷新动作
            isClose = true;
        }
    }

    if (isClose) {
        document.getElementById("btnOut").click();
    }
}

function GetCenterHeight() {
    return $(".l-layout-center").height();
}




//----------刷新处理记录条数
//刷新站内信息
function RefreshMessage() {
    $.ajax({
        cache: false,
        async: true,
        url: url + "Action=GetMessageCount",
        dataType: 'text',
        type: 'post',
        success: function (message) {
            $("#lblMessage_Count").html(message);
        }
    });
}

//-----------------------






function ShowError(fun, XMLHttpRequest, textStatus, errorThrown) {
    var mess = "Error! Please send this message to Administrator!<br/>";
    mess += "function:" + fun + "<br/>";
    mess += "XMLHttpRequest.status:" + XMLHttpRequest.status + "<br/>";
    mess += "XMLHttpRequest.readyState:" + XMLHttpRequest.readyState + "<br/>";
    mess += "textStatus:" + textStatus;
    toastrError(mess);
}